﻿package {
	import com.googlecode.milib.display.button.views.ButtonViewPlayTo;	
	import com.googlecode.milib.display.button.views.ButtonViewIniMidEnd;	
	import com.googlecode.milib.display.button.views.ButtonViewFourFrames;	
	import com.googlecode.milib.util.MLClassUtil;	
	import com.googlecode.milib.display.button.views.ButtonViewSound;	
	import com.googlecode.milib.display.button.views.ButtonViewContrast;	
	
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	
	import com.googlecode.milib.MILibMain;
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.dbg.SimpleTrace;
	import com.googlecode.milib.display.service.MLButton;
	import com.googlecode.milib.display.service.MLMC;
	import com.googlecode.milib.vo.MLEventInfo;	

	/**
	 * @author Marek Brun 'minim'
	 */
	public class ExampleButtonViewsMain extends MovieClip implements IMLBroadcasterListener {
		
		private var mlmc:MLMC;
		private var btnBVFourFrames:MLButton;
		private var btnBVPlayTo:MLButton;
		private var btnSound:MLButton;
		private var btnOthers:MLButton;

		public function ExampleButtonViewsMain() {
			stage.scaleMode=StageScaleMode.NO_SCALE; 
			stage.align=StageAlign.TOP_LEFT;
			MILibMain.init(this);
			
			//MLMC class make life little easer in this case
			mlmc=MLMC.forInstance(this);
			
			btnBVFourFrames=mlmc.getMLButton('btnFourFrames');
			btnBVFourFrames.addListener(this);
			
			//other way to setup auto view
			btnBVPlayTo=mlmc.getMLButton('btnPlayTo');
			btnBVPlayTo.addListener(this);
			
			//just create instance for viewers
			mlmc.getMLButton('btnContrast');			mlmc.getMLButton('btnGlow');
			MLButton.forInstance(MovieClip(getChildByName('btnIniMidEnd'))); //other way to do the same
			
			
			//manually setup button views
			btnSound=mlmc.getMLButton('btnA');
			btnSound.addButtonView(ButtonViewContrast.forInstance(mlmc.getMC('btnA')));			btnSound.addButtonView(ButtonViewSound.forInstance(MLClassUtil.createSoundFromLibrary('PongPublic')));
			
			btnOthers=mlmc.getMLButton('btnB');
			btnOthers.addButtonView(ButtonViewFourFrames.forInstance(mlmc.getMC('btnFourFrames')));
			btnOthers.addButtonView(ButtonViewContrast.forInstance(mlmc.getMC('btnContrast')));			btnOthers.addButtonView(ButtonViewPlayTo.forInstance(mlmc.getMC('btnPlayTo')));			btnOthers.addButtonView(ButtonViewIniMidEnd.forInstance(mlmc.getMC('btnIniMidEnd')));
			btnOthers.addButtonViews(btnSound.getButtonViews());
			btnOthers.addButtonViews(mlmc.getMLButton('btnGlow').getButtonViews());
		}
		
//********************************************************************************************
//		events for ExampleButtonViewsMain
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			if(ev.hero is MLButton && ev.event=='Press') {
				SimpleTrace.trace('something is pressed');
			}
			switch(ev.hero){
				case btnBVFourFrames:
					switch(ev.event) {
						case btnBVFourFrames.event_Press:
							SimpleTrace.trace('btnBVFourFrames.event_Press');
						break;
					}
				break;
				case btnBVPlayTo:
					switch(ev.event) {
						case btnBVPlayTo.event_Press:
							SimpleTrace.trace('btnBVPlayTo.event_Press');
						break;
					}
				break;
			}
		}//<<
		
	}
}
